package cn.gson.crm.model.service;

import cn.gson.crm.model.dao.*;
import cn.gson.crm.model.mapper.GgMapper;
import cn.gson.crm.model.pojos.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class Ggservice {
    @Autowired
    GgMapper ggMapper;
    @Autowired
    CpDao cpDao;
    @Autowired
    CategoryDao categoryDao;
    @Autowired
    CpxqDao cpxqDao;
    @Autowired
    SpecificationsDao specificationsDao;
    @Autowired
    SpecificationvalueDao specificationvalueDao;
    //根据类别查询规格
    public List<Specifications> ggselect(String lb){
        return ggMapper.selectgg(lb);
    }
    //查询类别
    public List<Category> bie(){
        return ggMapper.bie();
    }

    //查询规格名
    public List<Specifications> ming(){
        return ggMapper.ming();
    }

    //新增规格
    public void ggxz(Ggxz ggxz){

        Category category = ggxz.getCategory();
        Specifications specifications = ggxz.getGg();
        Specifications specifications1 = specificationsDao.save(specifications);

        for(int i=0;i<ggxz.getGgzhi().length;i++){
            SpecifValue specifValue = new SpecifValue();
            specifValue.setCategory3(category);
            specifValue.setSpecifications(specifications1);
            specifValue.setGgzValue(ggxz.getGgzhi()[i]);
            specificationvalueDao.save(specifValue);
        }

        System.out.println("类别id:"+category.getCategoryId());
        System.out.println("规格id:"+specifications1.getGgId());
    }
    //根据规格名称查询规格值
    public List<SpecifValue> ggmc(String ggmc,String gglb){
        return ggMapper.cxmc(ggmc,gglb);
    }

    //树形控件
    public List<Cate> cxlb(){
        return ggMapper.cxlb();
    }

    public List<SpecifValue> ggmcc(){
        return ggMapper.cxmcc();
    }

    //删除规格值
    @Transactional(transactionManager = "transactionManager")
    public void shan(Integer ggzId){
        specificationvalueDao.shan(ggzId);
    }


    public List<SpecifValue> zhi(Integer geid,Integer bieid){
        return ggMapper.zhi(geid,bieid);
    }

    public List<SpecifValue> cs(String mingzi,Integer leiming){
        return ggMapper.cs(mingzi,leiming);
    }
}
